package com.x.erp.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.ContractRegionDao;
import com.x.erp.manage.ContractRegionManage;
import com.x.erp.model.ContractRegion;
import com.x.erp.rpc.ContractRegionRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
@Service(interfaceName = "com.x.erp.rpc.ContractRegionRpcService", timeout = 60000)
public class ContractRegionService extends BaseService implements ContractRegionRpcService {

	@Autowired
	private ContractRegionDao contractRegionDao;

	@Autowired
	private ContractRegionManage contractRegionManage;

	@Override
	public List<ContractRegion> selectContractRegionList(ContractRegion contractRegion) {
		try {
			return contractRegionDao.selectContractRegionList(contractRegion);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public ContractRegion insertContractRegion(ContractRegion contractRegion) {
		try {
			return contractRegionManage.insertContractRegion(contractRegion);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public void updateContractRegion(ContractRegion contractRegion) {
		try {
			contractRegion.setContractRegionUpdateTime(this.getDate(0));
			contractRegionManage.updateContractRegion(contractRegion);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public void deleteContractRegion(ContractRegion contractRegion) {
		try {
			contractRegionManage.deleteContractRegion(contractRegion);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}
}
